package com.mingweicai.intergration.thread.orderprint;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import org.wildfly.common.lock.Locks;

public class Print3 implements Runnable{

  public static int flag;
  Lock lock = Locks.reentrantLock();
  Condition condition = lock.newCondition();
  int start ;
  int n;
  int cFlag ;
  int nFlag ;

  public Print3(int start, int n, int cFlag, int nFlag) {
    this.start = start;
    this.n = n;
    this.cFlag = cFlag;
    this.nFlag = nFlag;
  }

  @Override
  public void run() {
    for(int i=start; i<=n; i+=3){
      while(flag != cFlag) continue;
      System.out.println(i);
      flag = nFlag;
    }
  }

  public static void main(String args[]){
    new Thread(new Print2(1,100, -1, 1 )).start();
    new Thread(new Print2(2,100, 1, 2 )).start();
    new Thread(new Print2(3,100, 2, -1)).start();
  }
}
